package com.lightsaber.trade.cloth.dao.category;

import java.util.List;

import org.hibernate.Query;
import org.springframework.stereotype.Component;

import com.lightsaber.trade.core.dao.BaseDao;
import com.lightsaber.trade.cloth.entity.category.CategoryPlanner;

@Component
public class CategoryPlannerDao extends BaseDao<CategoryPlanner, String> {
    /**
     * delete by categoryNodeId
     */
    public void deleteByCategoryNodeId(final String categoryNodeId) {
        Query q = getSession().createQuery(
                "delete from CategoryPlanner c where c.categoryNode.id=:categoryNodeId");
        q.setParameter("categoryNodeId", categoryNodeId);

        q.executeUpdate();

    }

    public List<CategoryPlanner> findByCategoryNodeId(final String categoryNodeId) {
        return eq("categoryNode.id", categoryNodeId).list();
    }

    public long countBranchTreesByYear(final String nodeId, final String roleCode) {
        eq("categoryNode.id", nodeId);
        eq("roleCode", roleCode);
        return count();
    }
}
